package kickass2011;

import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

/**
 * this only test for enumeration
 * 
 * @author go4thx
 *
 */
public enum DataBaseType {

	MYSQL("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/mydb"),
	ORACLE("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@localhost:1521:sample"),
	DB2("com.ibm.db2.jdbc.app.DB2Driver", "jdbc:db2://localhost:5000/sample"),
	SQLSERVER("com.microsoft.jdbc.sqlserver.SQLServerDriver", "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb");

	private String driver;
	private String url;
	//-------------------------------------------------------constructor
	
	/**
	 * 
	 * @param driver 
	 * @param url
	 */
	DataBaseType(String driver,String url){
		this.driver = driver;
		this.url = url;
	}

	//--------------------------------------------------------public method
	/**
	* 获得数据库驱动
	* @return
	*/
	public String getDriver() {
		return driver;
	}

	/**
	* 获得数据库连接URL
	* @return
	*/
	public String getUrl() {
		return url;
	}
	
	//test 
	public static void main(String[] args) {
		//EnumMap 	
		EnumMap<DataBaseType, String> enumMap = new EnumMap<DataBaseType, String>(DataBaseType.class);
		//EnumSet 
		for(DataBaseType dataBaseType: EnumSet.allOf(DataBaseType.class)){
			enumMap.put(dataBaseType, "test EnumMap values");
		}
		
		Set<Map.Entry<DataBaseType, String>> set = 	enumMap.entrySet();
		for (Iterator<Entry<DataBaseType, String>> iterator = set.iterator(); iterator.hasNext();) {
			Map.Entry<DataBaseType, String> entry = iterator.next();
			System.out.println(entry.getKey() + ":" +  entry.getKey().driver + ">" + entry.getKey().url + " -> " + entry.getValue());
		}

	}
}